<template>
  <div>
    <el-select
      v-model="value"
      style="width: 80px;"
      placeholder="请选择"
      @change="onChange"
    >
      <el-option v-for="item in message" :key="item" :label="item" :value="item" :disabled="item===$i18n.locale" />
      <!-- <el-option label="英文" value="en" /> -->
    </el-select>
  </div>
</template>

<script>
import { setLang, getLang } from '@/utils/auth'
import langMessage from '@/I18n/messages'

export default {
  data() {
    return {
      value: getLang() || 'zh', // 记录的就是使用哪个语言包
      message: Object.keys(langMessage)
    }
  },

  created() {

  },

  methods: {
    onChange() {
      // console.log(this.value)
      // console.log(this.$i18n)
      this.$i18n.locale = this.value
      setLang(this.value)
      this.$message.success('切换语言成功')
      this.$router.go(0)
    }
  }
}
</script>

<style scoped lang='less'>

</style>
